package com.ydd.controller.admin;

import com.ydd.dto.SYSRoleInsertDTO;
import com.ydd.dto.SYSRolePageQueryDTO;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.SysRoleService;
import com.ydd.vo.RoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:43
 */
@Api(tags = "权限管理-角色管理")
@RestController
@RequestMapping("/admin/sys_role")
@Slf4j
public class SysRoleController {
    @Autowired
    SysRoleService sysRoleService;

    @GetMapping("/list")
    @ApiOperation("角色列表-分页")
    public Result<PageResult> listRole(SYSRolePageQueryDTO sysRolePageQueryDTO){
        PageResult<RoleVO> pageResult=sysRoleService.listRole(sysRolePageQueryDTO);
        return Result.success(pageResult);
    }


    @PostMapping("/update")
    @ApiOperation("角色修改")
    public Result updateRole(@RequestBody SYSRoleInsertDTO sysRoleInsertDTO){
        sysRoleService.updateRole(sysRoleInsertDTO);
        return Result.success();
    }

    @GetMapping("/rowInfo")
    @ApiOperation("角色详情")
    public Result<RoleVO> rowInfo(String id){
        RoleVO roleVO=sysRoleService.rowInfo(id);
        return Result.success(roleVO);
    }

    @GetMapping("/allData")
    @ApiOperation("角色列表-全部")
    public Result<List<RoleVO>> allData(){
        List<RoleVO> allDataVOList=sysRoleService.allData();
        return Result.success(allDataVOList);
    }

    @PostMapping("/add")
    @ApiOperation("角色添加")
    public Result addRole(@RequestBody SYSRoleInsertDTO sysRoleInsertDTO){
        sysRoleService.addRole(sysRoleInsertDTO);
        return Result.success();
    }

    @GetMapping("/del")
    @ApiOperation("角色删除")
    public Result delRole(String id){
        sysRoleService.delRole(id);
        return Result.success();
    }
}
